﻿using System;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using DevExpress.Spreadsheet;
using EasyLottery.Propertiy;
using EasyLottery.Utils;

namespace EasyLottery.View
{
    public partial class FormMain : Form
    {
        private const string Version = @"EasyLottery V1.0";
        private Label _titile;
        private Label _subTitle;

        private FormMainProperties FormMainProperties = new FormMainProperties();

        public FormMain()
        {
            InitializeComponent();
        }

        private void FormMain_Load(object sender, EventArgs e)
        {   
            //EasyLotteryProperties.Save();
            Init();
            LoadImg();

            this.KeyDown += FormMain_KeyDown;
        }

        private void FormMain_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == (Keys.Control | Keys.Alt | Keys.I))
            {
                FormImport formImport = new FormImport();
                formImport.ShowDialog();

                Worksheet worksheet = formImport.Worksheet;

            }
        }

        private void LoadImg()
        {
            var path = PathUtils.ComposeAbsolutePath(@"img\0.jpg");
            var imgBackGround = Image.FromFile(path);
            BackgroundImage = imgBackGround;
            BackgroundImageLayout = ImageLayout.Stretch;
        }

        private void Init()
        {
            Text = Version;
            StartPosition = FormStartPosition.CenterScreen;

            //全屏显示
            SetVisibleCore(false);
            FormBorderStyle = FormBorderStyle.None;
            WindowState = FormWindowState.Maximized;
            SetVisibleCore(true);

            _titile = new Label
            {
                Text = FormMainProperties.MainTile.Text,
                Location = new Point(0, FormMainProperties.MainTile.Y),
                AutoSize = true,
                BackColor = Color.Transparent,
                ForeColor = Color.Yellow,
                Font = new Font("微软雅黑", 80F, FontStyle.Bold, GraphicsUnit.Point, 134)
            };

            _subTitle = new Label
            {
                Text = FormMainProperties.SubTitle.Text,
                Location = new Point(0, FormMainProperties.SubTitle.Y),
                AutoSize = true,
                BackColor = Color.Transparent,
                ForeColor = Color.Yellow,
                Font = new Font("微软雅黑", 40F, FontStyle.Regular, GraphicsUnit.Point, 134)
            };

            //var btn = new Button
            //{
            //    Location = new Point(100, 400),
            //    Text = @"开始",
            //    Size = new Size(200, 100),
            //    BackgroundImage = Image.FromFile(PathUtils.ComposeAbsolutePath(@"button\0_On.png")),
            //    BackgroundImageLayout = ImageLayout.Stretch
            //};
            //btn.Click += Btn_Click;

            //Controls.Add(btn);
            Controls.Add(_titile);
            Controls.Add(_subTitle);
        }

        private void FormMain_Shown(object sender, EventArgs e)
        {
            MusicUtils.StopAndPlay(PathUtils.ComposeAbsolutePath(@"music\bg2.mp3"));
        }

        private void Btn_Click(object sender, EventArgs e)
        {
            MusicUtils.StopAndPlay(PathUtils.ComposeAbsolutePath(@"music\start2.mp3"));
        }

        private void FormMain_Paint(object sender, PaintEventArgs e)
        {
            //标题居中
            _titile.Location = LocationUtils.GetMiddleLocation(Size, _titile.Location, _titile.Size);
            //副标题居中
            _subTitle.Location = LocationUtils.GetMiddleLocation(Size, _subTitle.Location, _subTitle.Size);
            //副标题在标题下方
            _subTitle.Location = new Point(_subTitle.Location.X, _titile.Location.Y + _titile.Size.Height);
        }
    }
}
